package lime49.lockcrypt.mobile;

import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.io.file.*;

class GUI extends GameCanvas {
    private LockCrypt midlet;
    
    private Display display;
    
    private Graphics g;
    
    private Font boldFont, normalFont, smallFont;
    
    private int width = 0;
    private int height = 0;
    
    public GUI(LockCrypt midlet) {
        super(false);
        this.midlet = midlet;
        
        boldFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_BOLD, Font.SIZE_LARGE);
        normalFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
        smallFont = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_SMALL);
        
        setFullScreenMode(true);
        
        width = getWidth();
        height = getHeight();
        
        g = getGraphics();
        drawAbout();
    }
    public void drawAbout() {
        String message;
        g.setColor(0xffffff);
        g.fillRect(0, 0, width, height);
        flushGraphics();
        
        int y = 10;
        g.setColor(0x000000);
        g.setFont(boldFont);
        message = "LockCrypt J2ME";
        g.drawString(message, width/2 - (boldFont.stringWidth(message)/2), y, g.LEFT | g.TOP);
        y += boldFont.getHeight();
        
        Image logo = null;
        try {
            if(display.isColor()) {
                logo = Image.createImage("images/icon_64.png");
            } else {
                logo = Image.createImage("images/icon_bw.png");
            }
        } catch(IOException ignore) {/**/}
        g.drawImage(logo, width/2, y, Graphics.HCENTER | Graphics.VCENTER);
        y += logo.getHeight();
        
        g.setFont(normalFont);
        message = "Version "+midlet.LCVER;
        g.drawString(message, width/2 - (normalFont.stringWidth(message)/2), y, g.LEFT | g.TOP);
        y += normalFont.getHeight();
        
        g.setFont(normalFont);
        message = "http://www.lockcrypt.com/"+midlet.LCVER;
        g.drawString(message, width/2 - (smallFont.stringWidth(message)/2), y, g.LEFT | g.TOP);
        y += smallFont.getHeight();
    }
    protected void keyPressed(int keyCode) {
        midlet.displayMain();
    }
}
